// // --------------------------------------------------------------------------------------------------------------------
// // <copyright file="TermsAndConditionsForm.cs" company="Collaboris">
// //   Copyright Collaboris
// // </copyright>
// // <summary>
// //   
// // </summary>
// // --------------------------------------------------------------------------------------------------------------------

namespace DocRead.Selenium.Tests.DocRead.ControlObjects
{
    #region

    using Collaboris.ShareTest.Core;
    using Collaboris.ShareTest.SharePoint2010.ControlObjects;

    using OpenQA.Selenium;
    using OpenQA.Selenium.Remote;

    #endregion

    public class TermsAndConditionsForm : SPTModelBase
    {
        #region Constants and Fields

        public static string CtrlCancelButton = "ctl00_PlaceHolderMain_ctl00_BtnCancel";

        public static string CtrlOkButton = "ctl00_PlaceHolderMain_ctl00_RptControls_SaveButton";

        public static string CtrlTermsAndConditionsStatementErrorId =
            "ctl00_PlaceHolderMain_TermsAndConditionsSection_txtTermsAndConditionsTextBoxValidator";

        public static string CtrlTermsAndConditionsStatementId =
            "ctl00_PlaceHolderMain_TermsAndConditionsSection_txtTermsAndConditionsTextBox";

        #endregion

        #region Constructors and Destructors

        public TermsAndConditionsForm(RemoteWebDriver driver)
            : base(driver)
        {
        }

        #endregion

        #region Public Properties

        public IWebElement CancelButton
        {
            get
            {
                return this.WebDriver.FindElementById(CtrlCancelButton);
            }
        }

        public string MainStatement { get; set; }

        public IWebElement MainStatementElement
        {
            get
            {
                return this.WebDriver.FindElementById(CtrlTermsAndConditionsStatementId);
            }
        }

        public string MainStatementElementErrorMessage { get; set; }

        public IWebElement MainStatementElementErrorMessageElement
        {
            get
            {
                if (this.WebDriver.IsElementPresent(By.Id(CtrlTermsAndConditionsStatementErrorId)))
                {
                    return this.WebDriver.FindElementById(CtrlTermsAndConditionsStatementErrorId);
                }
                return null;
            }
        }

        public IWebElement OkButton
        {
            get
            {
                return this.WebDriver.FindElementById(CtrlOkButton);
            }
        }

        public string TopLevelError { get; set; }

        public IWebElement TopLevelErrorElement
        {
            get
            {
                return this.WebDriver.IsElementPresent(By.XPath(Locators.XpathTopLevelErrorIdentifier))
                           ? this.WebDriver.FindElementByXPath(Locators.XpathTopLevelErrorIdentifier)
                           : null;
            }
        }

        #endregion

        #region Public Methods

        public void RefreshForm()
        {
            this.MainStatement = this.MainStatementElement.GetAttribute("value");

            if (this.TopLevelErrorElement != null)
            {
                this.TopLevelError = this.TopLevelErrorElement.Text;
            }

            if (this.MainStatementElementErrorMessageElement != null)
            {
                this.MainStatementElementErrorMessage = this.MainStatementElementErrorMessageElement.Text;
            }
        }

        #endregion

        //
    }
}